package com.deer.wms.project.root.util;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;

/**
 * @Author: xu
 * @Date: 2021/08/29/14:52
 * @Description:
 */


public class DownloadUtils {
    public void download(ByteArrayOutputStream byteArrayOutputStream , HttpServletResponse response, String returnName) throws Exception {

        response.setContentType("application/octet-stream");
        StringBuilder contentDispositionValue = new StringBuilder();
        contentDispositionValue.append("attachment; filename=")
                .append(returnName)
                .append(";")
                .append("filename*=")
                .append("utf-8''")
                .append(returnName);

        response.setHeader("Content-disposition",contentDispositionValue.toString());
        ServletOutputStream outputStream = response.getOutputStream();  //得到输出流
        byteArrayOutputStream.writeTo(outputStream); //写到输出流
        byteArrayOutputStream.close(); //关闭
        outputStream.flush(); //刷数据


    }

}
